package com.xy.iot.common.enums;

import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;

/**
 * @author: niuniu
 * @Date: 2024/6/14 21:54
 * @Description: 命令枚举
 */
@Getter
public enum CommandEnum {
    TEST_DOME(10, "测试命令DOME"),
    CLIENT_PING(110, "客户端心跳"),
    SERVER_PING(111, "服务端响应返回心跳数据"),

    ;
    @ApiModelProperty("枚举唯一标识")
    private final Integer key;
    @ApiModelProperty("枚举描述")
    private final String value;

    /**
     * 创建命令数据，构造方法
     * @param key 枚举唯一标识
     * @param value 枚举描述
     */
    private CommandEnum(Integer key, String value) {
        this.key = key;
        this.value = value;
    }

    /**
     * 根据枚举唯一标识获取枚举
     * @param key 枚举唯一标识
     * @return
     */
    public static CommandEnum getCommandEnum(Integer key) {
        for (CommandEnum commandEnum : CommandEnum.values()) {
            if (commandEnum.getKey().equals(key)) {
                return commandEnum;
            }
        }
        return null;
    }
}
